package com.dhu.graph.basic.edge;

/**
 * @ Author ：snow
 * @ Date   ：Created in 2020-05-08
 * @ Description：加权图的边
 * @ Modified By：
 * @ Version:
 */
public class Edge implements Comparable<Edge> {
    private int v;
    private int w;
    private double weight;

    public Edge (int v, int w, double weight){
        this.v = v;
        this.w = w;
        this.weight = weight;
    }

    public int either(){
        return this.v;
    }
    public int other(int vertex){
        if (vertex == this.v) return this.w;
        else if (vertex == this.w) return this.v;
        else throw new RuntimeException("Hash No Such vertex" + vertex);
    }

    public double weight(){
        return this.weight;
    }


    @Override
    public int compareTo(Edge e) {
        return Double.compare(this.weight, e.weight);
    }
}
